<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<p>This tests to see if a mouse click inside an editable, focusable node focuses
that node. Normally, we focus a node on mouse down, but to make it easier to
drag selections containing editable pieces we delay focus until mouse up. The
editable table cell should be focused and you should see a 'Success' message
below.</p>
<div id="div" contenteditable onblur="handleBlur();"><table contenteditable="false" border="1"><tr><td>non-editable</td><td id="cell" contenteditable>editable</td></tr></table></div>
<div id="destination" contenteditable><br></div>
<div id="log"></div>
<script>
var blurred = false;
function handleBlur() {
    blurred = true;
}
var test = async_test('mouse up to move focus');
test.step(function() {
    if (!window.testRunner)
        return;
    var cell = document.getElementById('cell');
    cell.addEventListener('DOMBlurEvent', handleBlur);
    var div = document.getElementById('div');
    div.focus();
    document.execCommand('SelectAll');

    var x = cell.offsetParent.offsetLeft + cell.offsetLeft + cell.offsetWidth / 2;
    var y = cell.offsetParent.offsetTop + cell.offsetTop + cell.offsetHeight / 2;
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();

    assert_false(blurred, 'focus changed too early.');
    eventSender.mouseUp();
    window.setTimeout(function() {
        assert_true(blurred, 'mouse up moves focus');
        test.done();
    }, 0);
});
</script>
